//
//  WEIBO_GIRLSCell.m
//  GIFShow
//
//  Created by 陈凯 on 15/6/5.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "WEIBO_GIRLSCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "RepoterView.h"
@interface WEIBO_GIRLSCell ()
@property (nonatomic, strong) UIView * backgroundRoundView;
@property (nonatomic, strong) RepoterView * shareView;
@property (nonatomic, strong) UILabel * contentLabel;
@property (nonatomic, strong) UIImageView * contentImageView;

@end
@implementation WEIBO_GIRLSCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];

    }
    return self;
}

-(void)setupSubviews{
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    CGRect screenFrame = [UIScreen mainScreen].bounds;
    self.backgroundRoundView = [[UIView alloc]initWithFrame:screenFrame];
    self.backgroundRoundView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.backgroundRoundView.layer.borderWidth = 1;
    self.backgroundRoundView.layer.cornerRadius = 5;
    self.backgroundRoundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    self.contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 0)];
    self.contentLabel.numberOfLines = 0;
    self.contentImageView = [[UIImageView alloc]initWithFrame:CGRectMake(2, 2, self.frame.size.width - 4, 0)];
    [self.contentView addSubview:self.backgroundRoundView];
    [self.backgroundRoundView addSubview:self.contentLabel];
    [self.backgroundRoundView addSubview:self.contentImageView];
    // 顶
    self.shareView = [[RepoterView alloc]initWithFrame:CGRectMake(screenFrame.size.width*0.05, 0, screenFrame.size.width*0.9, 40)];
    [self.backgroundRoundView addSubview:self.shareView];
}
-(void)setBaseModel:(WEIBO_GIRLS *)baseModel{
    CGRect screenFrame = [UIScreen mainScreen].bounds;

    WEIBO_GIRLS * girl = (WEIBO_GIRLS*)baseModel;
    [super setBaseModel:girl];
    self.backgroundRoundView.frame = CGRectMake(5, 0, screenFrame.size.width - 10, self.contentLabel.frame.size.height+self.contentImageView.frame.size.height);
    self.contentLabel.text = [baseModel.wbody stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    NSLog(@"%@",self.contentLabel.text);
    self.contentLabel.frame = CGRectMake(self.backgroundRoundView.frame.size.width*0.05, 5, self.contentImageView.frame.size.width, 80);
    [self.contentLabel sizeToFit];
    
    NSURL * imageUrl = [NSURL URLWithString:baseModel.wpic_middle];
    if (imageUrl) {
        [self.contentImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.contentImageView.frame = CGRectMake(self.backgroundRoundView.frame.size.width * 0.05, self.contentLabel.frame.size.height+8, self.backgroundRoundView.frame.size.width*0.9, self.backgroundRoundView.frame.size.width*0.9 / girl.wpic_m_width.floatValue * girl.wpic_m_height.floatValue);
        NSLog(@"%@",self.contentImageView);
    }

    CGRect backFrame = self.backgroundRoundView.frame;
    
    self.shareView.frame = CGRectMake(0, self.contentLabel.frame.size.height + self.contentImageView.frame.size.height+self.backgroundRoundView.frame.size.width*0.05, self.backgroundRoundView.frame.size.width, self.backgroundRoundView.frame.size.width * 0.12);
    
    backFrame.size.height =   self.contentImageView.frame.size.height + self.contentLabel.frame.size.height+screenFrame.size.width * 0.18;
    self.backgroundRoundView.frame = backFrame;
    
    [self.shareView.likeButton setTitle:[NSString stringWithFormat:@"%ld",girl.likes.integerValue] forState:UIControlStateNormal];
    [self.shareView.likeButton setTitle:[NSString stringWithFormat:@"%ld",girl.likes.integerValue+1] forState:UIControlStateSelected];
    [self.shareView.dingButton setTitle:[NSString stringWithFormat:@"%ld",girl.comments.integerValue] forState:UIControlStateNormal];
    [self.shareView.dingButton setTitle:[NSString stringWithFormat:@"%ld",girl.comments.integerValue+1] forState:UIControlStateSelected];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
